package com.monitor.controller;

import com.monitor.commons.YXDate;
import com.monitor.dto.CallRecordsDTO;
import com.monitor.dto.CallRecordsPageDTO;
import com.monitor.modelExt.CallRecordsExt;
import com.monitor.pubInter.IBaseService;
import com.monitor.pubInter.exception.SkException;
import com.monitor.searchExt.CallRecordsSearchExt;
import com.monitor.service.ICallRecordsService;
import com.monitor.vo.CallRecordsDetailDomainVO;
import com.monitor.vo.CallRecordsDetailVO;
import com.monitor.vo.CallRecordsDomainVO;
import com.monitor.vo.CallRecordsListVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.*;

@RequestMapping("/callRecords/")
@RestController(value = "callRecordsController")
public class CallRecordsController extends ApiManageController<CallRecordsDTO, CallRecordsPageDTO, CallRecordsExt, CallRecordsSearchExt, CallRecordsDomainVO, CallRecordsDetailDomainVO, CallRecordsDetailVO, CallRecordsListVO, String> {
    private static final Logger log = LoggerFactory.getLogger(CallRecordsController.class);

    @Autowired
    private ICallRecordsService callRecordsService;

    @Override
    public IBaseService<CallRecordsExt, CallRecordsSearchExt, String> getBaseService() throws SkException {
        return callRecordsService;
    }


    /**
     * 获取通话记录
     *
     * @return
     * @throws Exception
     */
    @RequestMapping("queryRecords")
    public String queryRecords() throws Exception {
        // 创建 3 月 1 号的日期对象
        LocalDate startDate = LocalDate.of(2024, 12, 1);
        // 获取当前日期
        LocalDate endDate = LocalDate.of(2025,3,30);
        // 定义日期格式
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");

        // 遍历从开始日期到结束日期的所有日期
        for (LocalDate date = startDate;!date.isAfter(endDate); date = date.plusDays(1)) {
            java.time.ZonedDateTime zonedDateTime = date.atStartOfDay(ZoneId.systemDefault());
            callRecordsService.syncCallRecordData(Date.from(zonedDateTime.toInstant()));
        }
        return "success";
    }


}
